#include "Graph.h";
#include "Simple_window.h"
#include <iostream>

const int MAX_X = 800;
const int MAX_Y = 800;


Lines* get_grid(Point, int, int, int, int);

int main()
{
	try
	{
		Simple_window win(Point(100,100),MAX_X, MAX_Y, "Experiment");
		Lines* grid = get_grid(Point(0,0), 800, 800, 100, 100);
		win.attach(*grid);		

		Vector_ref<Graph_lib::Rectangle> rects;
		for (int i = 0; i < 800; i+=100)
		{
			rects.push_back(new Graph_lib::Rectangle(Point(i,i),100,100));
			rects[i/100].set_fill_color(Color::red);
			rects[i/100].set_color(Color::invisible);
			win.attach(rects[i/100]);
		}
		
		Vector_ref<Image> imgs;
		for (int i = 0; i < 3; ++i)
		{
			imgs.push_back(new Image(Point(i*200,0),"snow_cpp.gif"));
			imgs[i].set_mask(Point(0, 0), 200, 200);
			win.attach(imgs[i]);
		}

	
		Image photo(Point(0,200), "snow_cpp.gif");
		photo.set_mask(Point(0,0), 100, 100);
		win.attach(photo);
		
		while (win.wait_for_button())
		{
			if (photo.point(0).x+100 > 700)
			{
				if (photo.point(0).y+100 > 700)
					photo.move(0, -800);
				else
					photo.move(-800, 100);
			}
			
			photo.move(100, 0);
		}
		
		
		win.wait_for_button();
		return 0;
	}
	catch(exception& e)
	{
		std::cerr << e.what() << std::endl; 
		system("pause");
		return 1;
	}
	catch (...)
	{
		std::cerr << "unknown exception" << std::endl; 
		system("pause");
		return 2;
	}
}

Lines* get_grid(Point nw, int width, int height, int x_step , int y_step)
{
	Lines* grid = new Lines;
	for (int x = x_step; x < width; x+=x_step)
		grid->add(Point(x, nw.y), Point(x, nw.y+height));
	for (int y = y_step; y < height; y+=y_step)
		grid->add(Point(nw.x, y), Point(nw.x+width, y));
	return grid;
}
